package com.mnb.base.service.impl;

import com.mnb.base.entity.StRsvrR;
import com.mnb.common.utils.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import com.mnb.base.entity.StRsvrR;

import java.util.Date;
import java.util.List;

import com.mnb.base.mapper.StRsvrRMapper;
import com.mnb.base.service.StRsvrRService;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StRsvrRServiceImpl implements StRsvrRService {

    @Resource
    private StRsvrRMapper stRsvrRMapper;

    @Override
    public R getList(StRsvrR stRsvrR) {
        List<StRsvrR> list = stRsvrRMapper.getList(stRsvrR);
        return R.ok(list);
    }

    @Override
    public R insert(StRsvrR stRsvrR) {
        StRsvrR count = stRsvrRMapper.selectByPrimaryKey(stRsvrR.getTm(), stRsvrR.getStcd());
        if (count != null) {
            return R.fail("数据已存在");
        }
        stRsvrRMapper.insert(stRsvrR);
        return R.ok();
    }

    @Override
    public R update(StRsvrR stRsvrR) {
        stRsvrRMapper.updateByPrimaryKey(stRsvrR);
        return R.ok();
    }

    @Override
    @Transactional
    public R delete(List<StRsvrR> list) {
        for (StRsvrR stRsvrR : list) {
            stRsvrRMapper.deleteByPrimaryKey(stRsvrR.getTm(), stRsvrR.getStcd());
        }
        return R.ok();
    }

}
